<!--
@license
Copyright 2016 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-collapse/iron-collapse.html">

<dom-module id="tf-collapsable-pane">
  <template>
    <button
      class="heading"
      on-tap="togglePane"
      open-button$="[[opened]]"
    >
    <span class="name">[[name]]</span>
    <span class="count">
      <span>[[count]]</span>
    </span>
  </button>
    <iron-collapse opened="[[opened]]">
      <div class="content">
        <template is="dom-if" if="[[opened]]" restamp="[[restamp]]">
          <content></content>
        </template>
      </div>
    </iron-collapse>
    <style>
      :host {
        display: block;
        margin: 0 5px 1px 10px;
      }

      :host:first-of-type {
        margin-top: 20px;
      }
      
      :host:last-of-type {
        margin-bottom: 20px;
      }

      .heading {
        background-color: white;
        border: none;
        cursor: pointer;
        width: 100%;
        font-size: 15px;
        line-height: 1;
        box-shadow: 0 1px 5px rgba(0,0,0,0.2);
        padding: 10px 15px;
      }

      .content {
        padding: 15px;
        border: 1px solid #dedede;
        border-top: none;
        border-bottom-left-radius: 2px;
        border-bottom-right-radius: 2px;
        background: white;
      }

      [open-button] {
        border-bottom-left-radius: 0px !important;
        border-bottom-right-radius: 0px !important;
      }

      .name {
        float: left;
      }

      .count {
        float: right;
        margin-right: 5px;
        font-size: 12px;
        color: var(--paper-grey-500);
      }
    </style>
  </template>
  <script>
    Polymer({
      is: "tf-collapsable-pane",
      properties: {
        opened: {type: Boolean, value: false},
        restamp: {type: Boolean, value: true},
        name: {type: String, observer: "hide"},
        count: {type: Number},
      },
      hide: function() {
        this.opened = false;
      },
      togglePane: function() {
        this.opened = !this.opened;
      }
    });
  </script>

</dom-module>
